<?php

namespace frontend\models;

/**
 * @author  shuang
 * @date    2016-10-29 9:35:58
 * @version V1.0
 * @desc    
 */
use common\models\TaskTop;
use Yii;
use common\components\MTools;
use yii\behaviors\TimestampBehavior;

class WB_TaskTop extends TaskTop {
    /*
     * 设置表操作行为动作
     * return array
     */

    public function behaviors() {
        return[
            [
                'class' => TimestampBehavior::className()
            ]
        ];
    }

    /*
     * 添加置顶任务
     * @params $taskid
     * @params 置顶多久 defalut  12小时
     */

    public static function createTasktop($taskid, $top_at = 12) {
        $result = WB_TaskTop::find()->where("taskid=$taskid")->one();
        if (!$result instanceof WB_TaskTop) {
            $model = new WB_TaskTop();
            $model->taskid = $taskid;
            $begin = time();
            $model->begin_at = $begin;
            $model->end_at = $model->begin_at + $top_at * 3600;
            return MTools::saveModel($model);
        } else {
            return ["errors"=>["taskid"=>["任务已被置顶，请不要重复操作！"]]];
        }
    }

}
